Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement judgedaemon fixme's #2745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vmcj
Copy link
Member

@vmcj vmcj commented Oct 20, 2024

Based on feedback by @meisterT most of the error( calls are now changed to disable( calls to display this in the webinterface.

I'll do some squashing after getting approval.

Part of this is also put in #2809 so it's better to discuss/merge that one first and afterwards discuss the parsing of the CLI options.

@vmcj vmcj requested a review from meisterT October 20, 2024 09:40
@vmcj vmcj force-pushed the judgedaemon_returncode branch from 136028a to b455297 Compare October 21, 2024 05:55
@vmcj vmcj force-pushed the judgedaemon_returncode branch from b455297 to 9e00e09 Compare October 27, 2024 11:18
judge/judgedaemon.main.php Outdated Show resolved Hide resolved
judge/judgedaemon.main.php Outdated Show resolved Hide resolved
@vmcj vmcj force-pushed the judgedaemon_returncode branch from cec1019 to d6f20c2 Compare November 13, 2024 21:55
@vmcj vmcj force-pushed the judgedaemon_returncode branch 2 times, most recently from 3c22760 to 8cf34b2 Compare November 14, 2024 21:42
@vmcj vmcj requested review from meisterT and eldering November 14, 2024 21:44
Copy link
Member

@meisterT meisterT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just reviewing commit 936fc63 - I think it would be good to split this PR into multiple smaller ones that are independent.

judge/judgedaemon.main.php Show resolved Hide resolved
judge/judgedaemon.main.php Outdated Show resolved Hide resolved
@vmcj vmcj force-pushed the judgedaemon_returncode branch 2 times, most recently from 4cf0179 to 348ea2d Compare November 22, 2024 14:57
echo "Error: parsing options failed.\nPlease check: `register_argc_arg` in php.ini.\n";
usage();
}
$unknown = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be clearer:

Suggested change
$unknown = false;
$unknown_option = false;

Comment on lines 34 to 35
if (str_starts_with($arg, '-') && !array_key_exists(ltrim($arg, '-'), $options)) {
echo "Error: Unknown option: $arg\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if you pass multiple options like -df.

The documentation on this is not very clear. You can encounter the `False` by using unset($argv) which would be a misconfiguration so the error message is now also improved.

A better explanation can be found here: https://bugs.php.net/bug.php?id=81352

Which has those comments;
```
 [2021-08-12 15:19 UTC] [email protected]
Prior to PHP 8.0.0, FALSE was returned if the function was called
with unexpected parameters or parameter types.  Most other
functions returned NULL in that case.  Anyhow, there is no need to
document that, since this is actually undefined behavior[1].

For all relevant PHP versions, FALSE will also be returned, if
neither $_SERVER nor $argv exists or are not arrays.

[1] <https://www.php.net/manual/en/functions.internal.php>

 [2022-11-26 06:42 UTC] schamberumarcelo at gmail dot com
getopt() will return an empty array if there is no error in splitting strings to args variable. GetOptions() will return a true value if the command line could be processed successfully. Otherwise, it will write error messages using die() and warn(). (https://www.imyccpay.com)github.com
```
 given that we run PHP>8.0 and the explanation that parsing will stop for the first non-option I think we'll never encounter the false in practice. To be save we now check the shortoptions string for the right format.

To be sure an internal function is now added which does some extra parsing to find unknown arguments, alternative would be to use: (https://www.php.net/manual/en/function.getopt.php#83414).
@vmcj vmcj force-pushed the judgedaemon_returncode branch from 578eda8 to 00f5ab4 Compare November 22, 2024 16:12
foreach($long_options as $long_option) {
$stripped_arg = substr($arg, 2);
if (str_starts_with($long_option, $stripped_arg) && $stripped_arg !== $long_option) {
echo "Error: Shorten long options is not supported: $arg\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Error: Shorten long options is not supported: $arg\n";
echo "Error: shortening long options is not supported: $arg\n";

if (str_starts_with($long_option, $stripped_arg) && $stripped_arg !== $long_option) {
echo "Error: Shorten long options is not supported: $arg\n";
$unknown_option = true;
} elseif (!array_key_exists($stripped_arg, $options)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work with something like --my-long-option=foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants